import 'package:demo/views/login/login_index_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:demo/event/event_setting.dart';
import 'package:demo/views/base/base_controller.dart';
import 'package:demo/json/json_auth.dart';
import 'package:demo/tools/tools_enum.dart';
import 'package:demo/tools/tools_storage.dart';

class MineSafetyController extends BaseController {
  TextEditingController textEditingController = TextEditingController();
  LocalUser localUser = ToolsStorage().local();
  // 退出登录
  Future<void> logout() async {
    // 执行
    await JsonAuth.logout();
    // 提醒
    EasyLoading.showToast('退出成功');
    // 返回
    Get.back();
  }

  // 用户注销
  Future<void> deleted() async {
    // 跳转
    Get.offAllNamed(LoginIndexView.routeName);
    // 提醒
    EasyLoading.showToast('注销成功');
    // 返回
    Get.back();
  }

  @override
  void onInit() {
    super.onInit();
    // 监听
    subscription = EventSetting().event.stream.listen((model) {
      if (SettingType.mine != model.setting) {
        return;
      }
      localUser = ToolsStorage().local();
      update();
    });
  }
}
